package com.zl.tcbnewcar.view;

import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by zhagnlei on 2018/3/30.
 * 这个popupWindow是用来解决在7.0以及8.0中位置显示不正确的
 */
public class PopupWindow extends android.widget.PopupWindow {

    public PopupWindow(Context context) {
        super(context);
    }

    public PopupWindow(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public PopupWindow(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public PopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public PopupWindow() {
    }

    public PopupWindow(View contentView) {
        super(contentView);
    }

    public PopupWindow(int width, int height) {
        super(width, height);
    }

    public PopupWindow(View contentView, int width, int height) {
        super(contentView, width, height);
    }

    public PopupWindow(View contentView, int width, int height, boolean focusable) {
        super(contentView, width, height, focusable);
    }

    @Override
    public void showAsDropDown(View anchorView, int xoff, int yoff) {
        if (Build.VERSION.SDK_INT >= 24) {
            Rect visibleFrame = new Rect();
            anchorView.getGlobalVisibleRect(visibleFrame);
            int height = anchorView.getResources().getDisplayMetrics().heightPixels - visibleFrame.bottom;
            super.setHeight(height);
            super.showAsDropDown(anchorView, xoff, yoff);
        } else {
            super.showAsDropDown(anchorView, xoff, yoff);
        }
    }

    @Override
    public void showAsDropDown(View anchorView) {
        if (Build.VERSION.SDK_INT >= 24) {
            Rect visibleFrame = new Rect();
            anchorView.getGlobalVisibleRect(visibleFrame);
            int height = anchorView.getResources().getDisplayMetrics().heightPixels - visibleFrame.bottom;
            super.setHeight(height);
            super.showAsDropDown(anchorView);
        } else {
            super.showAsDropDown(anchorView);
        }
    }

}
